package com.aichat.ai_chatbackend.common;

import com.aichat.ai_chatbackend.model.enums.ErrorCode;
import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 通用返回类
 */
@Data

public class BaseResponse<T> implements Serializable {

    private int code;

    private T data;

    private Map<String,Object> extraData = new HashMap<>();

    private String message;

    public BaseResponse(int code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    // 新增方法：添加扩展数据
    public BaseResponse<T> addData(String key, Object value) {
        this.extraData.put(key, value);
        return this;
    }

    public BaseResponse(int code, T data) {
        this(code, data, "");
    }

    public BaseResponse(int code, String messagge) {
        this(code, null,messagge);
    }

    public BaseResponse(ErrorCode errorCode) {
        this(errorCode.getCode(), null, errorCode.getMessage());
    }

}
